"""HAL

class UserSchema(halogen.Schema):
    self = halogen.Link('#self')
    userID = halogen.Attr(attr='userid')
    avatar = halogen.Attr()


class UserCollection(halogen.Schema):
    self = halogen.Link('#self')
    next = halogen.Link('#next')
    prev = halogen.Link('#prev')
    users = halogen.Attr(
        halogen.types.List(UserSchema)
    )

Sample

USER = {
    'userid': 'Text{用户编号}',
    'avatar': 'Text{头像}',
}
"""

HEAD = """\
import halogen


class ProblemSchema(halogen.Schema):
    type = halogen.Attr()
    title = halogen.Attr()
    status = halogen.Attr()
    detail = halogen.Attr()
    instance = halogen.Attr()
"""

TEMPLATE = """

class {{ classname }}Schema(halogen.Schema):
    \"\"\"{{ title }}
    {{ docs }}
    Auto Generated Code.
    \"\"\"
    self = halogen.Link(attr=lambda arg: '#self')
{% for column in columns %}\
{% if column[1][0] and column[1][1] %}\
    {{ column[0][1] }} = halogen.Attr(
        {{ column[1][1] }},
        {{ column[1][0] }}
    )
{% elif column[1][0] %}\
    {{ column[0][1] }} = halogen.Attr({{ column[1][0] }})
{% elif column[1][1] %}\
    {{ column[0][1] }} = halogen.Attr(
        {{ column[1][1] }}
    )
{% else %}\
    {{ column[0][1] }} = halogen.Attr()
{% endif %}\
{% endfor %}

class {{ classname }}Collection(halogen.Schema):
    self = halogen.Link(attr=lambda arg: '#self')
    next = halogen.Link(attr=lambda arg: '#next')
    prev = halogen.Link(attr=lambda arg: '#prev')
    {{ tablename }} = halogen.Embedded(
        halogen.types.List({{ classname }}Schema)
    )

"""

SAMPLE_TEMPLATE = """
{{ classname | upper }} = {
{% for column in columns %}\
{% if column[2].lower() == 'datetime' %}\
    '{{ column[1] | lower }}': datetime.datetime.now(),  # {{ column[0] }}
{% elif column[2].lower() == 'date' %}\
    '{{ column[1] | lower }}': datetime.datetime.now().date(),  # {{ column[0] }}
{% elif column[2].lower() == 'time' %}\
    '{{ column[1] | lower }}': datetime.datetime.now().time(),  # {{ column[0] }}
{% else %}\
    '{{ column[1] | lower }}': '{{ column[2] }}',  # {{ column[0] }}
{% endif %}\
{% endfor %}\
}
"""
